<template>
	<view class="container">
		<fu-navbar title="巡检详情" bgColor="#0f68f0" color="#fff" isBackText></fu-navbar>
		<view class="tab-box">
			<view class="tab" :class="{'tab-active': tabCurrent == 0}" @click="tabChange(0)">基本信息</view>
			<view class="tab" :class="{'tab-active': tabCurrent == 1}" @click="tabChange(1)">工作项</view>
			<view class="tab" :class="{'tab-active': tabCurrent == 2}" @click="tabChange(2)"
				v-if="state&&state != 1&&state!=5">巡检处理</view>
		</view>
		<view style="margin-top: 90rpx;"></view>
		<block v-if="tabCurrent == 0">
			<view class="box margin-t-32">
				<view class="flex align-center padding-tb-24 border-b-c9">
					<image src="../../../static/images/icon31.png" mode="widthFix" class="t-icon"></image>
					<text class="title">基本信息</text>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32">
					<view class="label">巡检单号</view>
					<view class="flex align-center">
						<view class="">{{oneInfo.code}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32">
					<view class="label">所属区域</view>
					<view class="flex align-center">
						<view class="">{{region}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32">
					<view class="label">所属系统</view>
					<view class="flex align-center">
						<view class="">{{system}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32">
					<view class="label">所属子系统</view>
					<view class="flex align-center">
						<view class="">{{subSystem}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32" v-if="state == 5">
					<view class="label">完成时间</view>
					<view class="flex align-center">
						<view class="">{{patrolDetail.endTime}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between border-b-c9 padding-tb-32" v-else>
					<view class="label">巡检时间</view>
					<view class="flex align-center">
						<view class="">{{oneInfo.startDay}} {{oneInfo.startTime}}</view>
					</view>
				</view>
				<view class="item flex align-center justify-between padding-tb-32">
					<view class="label">巡检人</view>
					<view class="flex align-center">
						<view class="">{{oneInfo.patrolEmployee}}</view>
					</view>
				</view>
			</view>
			<view class="box margin-t-32" v-if="state == 1">
				<view class="flex align-center padding-tb-24 border-b-c9">
					<image src="../../../static/images/icon31.png" mode="widthFix" class="t-icon"></image>
					<text class="title">审核</text>
				</view>
				<view class="flex padding-tb-24 fs-28">
					<view class="sh-label">审核意见</view>
					<textarea placeholder="请输入内容" placeholder-class="pla-tar" class="tar"></textarea>
				</view>
			</view>
		</block>
		<view class="box margin-t-32" v-if="tabCurrent == 1">
			<view class="border-b flex align-center justify-between padding-tb-24 border-b-c9">
				<view class="flex align-center">
					<image src="../../../static/images/icon33.png" mode="widthFix" class="work-icon margin-r-12">
					</image>
					<view class="title" v-if="state == 1">设置巡检工作项</view>
					<view class="title" v-else>巡检工作项</view>
				</view>
				<view class="flex align-center" @click="navTo(`/pages/inspection/works/index?planType=2`)"
					v-if="state == 1">
					<image class="margin-r-12" src="../../../static/images/add.png" mode="aspectFill"
						style="width: 42rpx;height: 42rpx;"></image>
					<text class="fs-28" style="color: #1296db;">新增工作项</text>
				</view>
			</view>
			<!-- <view class="flex align-center justify-between padding-tb-12 border-b-c9" v-for="(item, index) in taskList" :key="index">
				<view class="over-hidden">
					<view class="fs-28 text-ellipsis">{{item.taskName}}</view>
					<view class="fs-26 margin-t-18" style="color: #dcdcdc;">{{item.taskDesc}}</view>
				</view>
				<view class="flex-shrink flex align-center" @click="toggleTab('selector', item.id, index)">
					<image src="../../../static/images/dui.png" class="work-status" v-if="item.state == 2"></image>
					<image src="../../../static/images/error.png" class="work-status" v-else-if="item.state == 3"></image>
					<image src="../../../static/images/icon43.png" class="work-status" v-else-if="item.state == 4"></image>
					<image src="../../../static/images/arrow-r.png" style="width: 32rpx;height: 32rpx;" v-else></image>
				</view>
			</view> -->
			<block v-for="(item, index) in taskList" :key="index">
				<view class="flex align-center justify-between padding-tb-12 border-b-c9">
					<view class="flex-1 over-hidden" @click="showTask(index)">
						<view class="flex align-center">
							<text class="fs-28">{{item.emTypeName}}</text>
							<image src="../../../static/images/icon47.png" class="hidden" v-if="!item.show"></image>
							<image src="../../../static/images/icon47.png" class="show" v-else></image>
						</view>
						<view class="fs-26 color-a">{{item.name}}</view>
						<view class="fs-26 color-a">{{item.code}}</view>
					</view>
					<switch color="#1abc9c" :checked="item.state == 1 ? false : true"
						@change="changeTask($event, item)"></switch>
				</view>
				<view class="border-b-c9 padding-tb-10" v-for="(child, childx) in item.taskList" :key="childx"
					v-if="item.show">
					<view class="flex align-center justify-between">
						<image src="../../../static/images/icon1.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '耳听/目视'"></image>
						<image src="../../../static/images/icon2.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '测温枪'"></image>
						<image src="../../../static/images/icon3.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '目视'"></image>
						<image src="../../../static/images/icon4.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '手动处理'"></image>
						<image src="../../../static/images/icon5.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '耳听'"></image>
						<image src="../../../static/images/icon6.jpg"
							style="width: 60rpx; height: 60rpx;flex-shrink: 0;" v-if="child.way == '仪表读数'"></image>
						<view class="flex-1 over-hidden padding-lr-16">
							<view class="fs-28">{{child.project}}</view>
							<view class="fs-26 color-a">{{child.standard}}</view>
						</view>
						<view class="flex align-center flex-shrink" v-if="child.isRecorded == 1">
							<!-- @click="toSelect(child, childx, index)" -->
							<input placeholder="请输入" placeholder-class="work-pla-ipt" class="work-ipt"
								v-model="child.recordedValue" :disabled="state == 3 ? false : true"
								@blur="taskBlur($event, child, index, childx)" />
						</view>
						<!-- <view class="flex-shrink flex align-center" @click="toggleTab('selector', child.id, index, childx)" v-else>
							<text class="fs-26 padding-lr-12 color-gray" v-if="child.state != 2 && child.state != 3 && child.state != 4">请选择</text>
							<image src="../../../static/images/dui.png" class="work-status" v-if="child.state == 2"></image>
							<image src="../../../static/images/error.png" class="work-status" v-else-if="child.state == 3"></image>
							<image src="../../../static/images/icon43.png" class="work-status" v-else-if="child.state == 4"></image>
							<image src="../../../static/images/arrow-r.png" style="width: 32rpx;height: 32rpx;" v-else></image>
						</view> -->
					</view>
					<view class="flex align-center margin-t-16 margin-b-10">
						<view class="flex align-center justify-center flex-1"
							@click="updateWorkState(2, child, childx, index)">
							<block>
								<image src="../../../static/images/select-action.png" class="select-icon"
									v-if="child.state == 1||child.state == 2"></image>
								<image src="../../../static/images/no-select.png" class="select-icon" v-else></image>
							</block>
							<text class="fs-26">正常</text>
						</view>
						<view class="flex align-center justify-center flex-1"
							@click="updateWorkState(3, child, childx, index)">
							<block>
								<image src="../../../static/images/select-action.png" class="select-icon"
									v-if="child.state == 3"></image>
								<image src="../../../static/images/no-select.png" class="select-icon" v-else></image>
							</block>
							<text class="fs-26">异常</text>
						</view>
						<view class="flex align-center justify-center flex-1"
							@click="updateWorkState(4, child, childx, index)">
							<block>
								<image src="../../../static/images/select-action.png" class="select-icon"
									v-if="child.state == 4"></image>
								<image src="../../../static/images/no-select.png" class="select-icon" v-else></image>
							</block>
							<text class="fs-26">待维修</text>
						</view>
					</view>
				</view>
			</block>

			<view class="flex justify-center align-center" style="height: 200rpx;" v-if="taskList.length == 0">
				<image src="../../../static/empty/no-data.png" mode="widthFix" style="width: 160rpx;"></image>
			</view>
			<block v-if="state != 1">
				<view class="flex align-center justify-between padding-tb-24 border-b-c9 margin-t-30">
					<view class="flex align-center">
						<image src="../../../static/images/icon34.png" mode="widthFix" class="work-icon margin-r-12">
						</image>
						<view class="title">巡检异常记录</view>
					</view>
				</view>
				<view class="flex fs-28 padding-tb-24 justify-between">
					<view class="label flex-shrink">异常拍照：</view>
					<view class="flex align-center flex-1 flex-wrap">
						<view class="yc-imgs" v-for="(item, index) in ycPics" :key="index">
							<image :src="`${read_url}${item.fileCode}`" class="img"></image>
							<image src="../../../static/images/close.png" class="close"
								@click.stop="delFile(item, index, 'ycImg')"></image>
						</view>
						<view class="yc-imgs">
							<image src="../../../static/images/icon41.png" mode="widthFix"
								@click="uploadImg('img', 'yc')" class="img" style="background-color: transparent;"
								v-if="ycPics.length < 9&&state!=5&&state!=4"></image>
						</view>
					</view>
				</view>
				<view class="flex fs-28 padding-tb-24">
					<view class="label flex-shrink">异常视频：</view>
					<view class="flex align-center flex-1 flex-wrap">
						<block v-for="(item, index) in ycVideo" :key="index">
							<view class="yc-imgs" @click="playVideo(item, 'yc', index)" v-if="!item.isPlay">
								<image src="" mode="aspectFill" lazy-load class="img" style="background-color: #000;">
								</image>
								<image class="v-play" src="../../../static/images/video-bg.png"></image>
								<image src="../../../static/images/close.png" class="close"
									@click.stop="delFile(item, index, 'ycVideo')"></image>
							</view>
							<view class="yc-imgs" v-else>
								<video :src="`${read_url}${item.fileCode}`" class="img" :id="`myVideo${index}`"
									@fullscreenchange="fullscreenchange($event, index)"
									@ended="videoEnd($event, index)"></video>
							</view>
						</block>
						<view class="yc-imgs" v-if="ycVideo.length < 9&&state!=5&&state!=4">
							<image src="../../../static/images/icon29.png" mode="widthFix" class="img"
								@click="uploadImg('video', 'yc')" style="background-color: transparent;"></image>
						</view>
					</view>
				</view>
				<view class="flex fs-28 padding-tb-24">
					<view class="label flex-shrink">异常音频：</view>
					<view class="flex flex-wrap yc-audio over-hidden">
						<view class="flex align-center over-hidden padding-tb-12 over-hidden"
							@click="playAudio(item, index)" v-for="(item, index) in ycAudio" :key="index">
							<image src="../../../static/images/play.png" mode="aspectFill" class="play"
								v-if="!item.isPlay"></image>
							<image src="../../../static/images/stop.png" mode="aspectFill" class="play" v-else></image>
							<view class="audio-url text-ellipsis">{{item.fileCode}}</view>
							<image src="../../../static/images/delete.png" mode="widthFix" style="width: 32rpx;"
								class="margin-l-24 flex-shrink" @click.stop="delFile(item, index, 'ycAudio')"></image>
						</view>
					</view>
					<view class="flex-shrink padding-lr-24" @longtap="longpressBtn" @touchmove="handleTouchMove"
						@touchstart="longpressBtn" @touchend="touchendBtn($event, 'yc')" @click="touchAudioBtn()"
						v-if="ycAudio.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon27.png" mode="widthFix" style="width: 68rpx;"></image>
					</view>
				</view>
				<view class="flex fs-28 padding-tb-24">
					<view class="label flex-shrink">异常说明：</view>
					<textarea placeholder="请输入内容" placeholder-class="pla-tar" class="yc-tar"
						v-model="orderException"></textarea>
				</view>
			</block>
		</view>
		<block v-if="tabCurrent == 2">
			<view class="box margin-t-32">
				<view class="border-b flex align-center justify-between padding-tb-24 border-b-c9">
					<view class="flex align-center">
						<image src="../../../static/images/icon39.png" mode="widthFix" class="work-icon margin-r-12">
						</image>
						<view class="title">巡检处理</view>
					</view>
				</view>
				<view class="flex align-center justify-between border-b-c9 padding-tb-32 fs-28">
					<view>故障类型</view>
					<view class="flex align-center" @click="toggleTab('type')">
						<view v-if="typeValue.dictName">{{typeValue.dictName}}</view>
						<image src="../../../static/images/arrow-r.png" class="arrow-r" style="width: 32rpx;"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="flex align-center justify-between border-b-c9 padding-tb-32 fs-28">
					<view>故障原因</view>
					<view class="flex align-center" @click="toggleTab('reason')">
						<view v-if="reasonValue.dictName">{{reasonValue.dictName}}</view>
						<image src="../../../static/images/arrow-r.png" class="arrow-r" style="width: 32rpx;"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="flex align-center justify-between border-b-c9 padding-tb-32 fs-28">
					<view>设备状态</view>
					<view class="flex align-center" @click="toggleTab('state')">
						<view v-if="stateValue.dictName">{{stateValue.dictName}}</view>
						<image src="../../../static/images/arrow-r.png" class="arrow-r" style="width: 32rpx;"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="padding-tb-32 fs-28">
					<view>处理方法及结果</view>
					<textarea placeholder="请描述处理方法及处理结果..." placeholder-class="pla-tra" class="tra"
						v-model="disposeResult" :disabled="state == 5 ? true : false"></textarea>
				</view>
			</view>
			<view class="flex padding-tb-24 padding-lr-24 fs-32 text-bold">处理前信息</view>
			<view class="box">
				<view class="cl-item flex justify-between border-b-f7">
					<text class="label flex-shrink">音频</text>
					<view class="con over-hidden">
						<view class="flex align-center over-hidden padding-tb-12" @click="playAudio(item, index, 'old')"
							v-for="(item, index) in oldAudio" :key="index">
							<image src="../../../static/images/play.png" mode="aspectFill" class="play"
								v-if="!item.isPlay"></image>
							<image src="../../../static/images/stop.png" mode="aspectFill" class="play" v-else></image>
							<view class="audio text-ellipsis">{{item.fileCode}}</view>
							<image src="../../../static/images/delete.png" mode="widthFix" style="width: 32rpx;"
								class="margin-l-24 flex-shrink" @click.stop="delFile(item, index, 'oldAudio')"></image>
						</view>
					</view>
					<view class="flex-shrink padding-lr-24" @longtap="longpressBtn" @touchmove="handleTouchMove"
						@touchstart="longpressBtn" @touchend="touchendBtn($event, 'old')" @click="touchAudioBtn()"
						v-if="oldAudio.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon27.png" mode="widthFix" class="a-icon"></image>
					</view>
				</view>
				<view class="cl-item flex border-b-f7">
					<text class="label flex-shrink">图片</text>
					<view class="flex align-center flex-1 flex-wrap">
						<view class="img-box" v-for="(item, index) in oldPics" :key="index">
							<image :src="`${read_url}${item.fileCode}`" mode="aspectFit" class="img"
								@click="previewImg(item, 2)"></image>
							<image src="../../../static/images/close.png" class="close"
								@click.stop="delFile(item, index, 'oldImg')"></image>
						</view>
					</view>
					<view class="flex-shrink padding-lr-24" v-if="oldPics.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon28.png" mode="widthFix" class="i-icon"
							@click="uploadImg('img', 'old')"></image>
					</view>
				</view>
				<view class="cl-item flex justify-between">
					<text class="label flex-shrink">视频</text>
					<view class="flex align-center flex-1 flex-wrap">
						<block v-for="(item, index) in oldVideo" :key="index">
							<view class="img-box" v-if="!item.isPlay" @click.stop="playVideo(item, 'old', index)">
								<image src="" mode="aspectFill" lazy-load class="img" style="background-color: #000;">
								</image>
								<image src="../../../static/images/video-bg.png" mode="aspectFill" class="v-play">
								</image>
								<image src="../../../static/images/close.png" class="close"
									@click.stop="delFile(item, index, 'oldVideo')"></image>
							</view>
							<view class="img-box" v-else>
								<video :src="`${read_url}${item.fileCode}`" class="img" :id="`oldVideo${index}`"
									@fullscreenchange="fullscreenchange($event, index, 'old')"
									@ended="videoEnd($event, index, 'old')"></video>
							</view>
						</block>
					</view>
					<view class="flex-shrink padding-lr-24" v-if="oldVideo.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon29.png" mode="widthFix" class="i-icon"
							@click="uploadImg('video', 'old')"></image>
					</view>
				</view>
			</view>
			<view class="flex padding-tb-24 padding-lr-24 fs-32 text-bold">处理后信息</view>
			<view class="box">
				<view class="cl-item flex justify-between border-b-f7">
					<text class="label flex-shrink">音频</text>
					<view class="con over-hidden">
						<view class="flex align-center over-hidden padding-tb-12" @click="playAudio(item, index, 'new')"
							v-for="(item, index) in newAudio" :key="index">
							<image src="../../../static/images/play.png" mode="aspectFill" class="play"
								v-if="!item.isPlay"></image>
							<image src="../../../static/images/stop.png" mode="aspectFill" class="play" v-else></image>
							<view class="audio text-ellipsis">{{item.fileCode}}</view>
							<image src="../../../static/images/delete.png" mode="widthFix" style="width: 32rpx;"
								class="margin-l-24 flex-shrink" @click.stop="delFile(item, index, 'newAudio')"></image>
						</view>
					</view>
					<view class="flex-shrink padding-lr-24" @longtap="longpressBtn" @touchmove="handleTouchMove"
						@touchstart="longpressBtn" @touchend="touchendBtn($event, 'new')" @click="touchAudioBtn()"
						v-if="newAudio.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon27.png" mode="widthFix" class="a-icon"></image>
					</view>
				</view>
				<view class="cl-item flex border-b-f7">
					<text class="label flex-shrink">图片</text>
					<view class="flex align-center flex-1 flex-wrap">
						<view class="img-box" v-for="(item, index) in newPics" :key="index">
							<image :src="`${read_url}${item.fileCode}`" mode="aspectFit" class="img"
								@click="previewImg(item, 2)"></image>
							<image src="../../../static/images/close.png" class="close"
								@click.stop="delFile(item, index, 'newImg')"></image>
						</view>
					</view>
					<view class="flex-shrink padding-lr-24" v-if="newPics.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon28.png" mode="widthFix" class="i-icon"
							@click="uploadImg('img', 'new')"></image>
					</view>
				</view>
				<view class="cl-item flex justify-between">
					<text class="label flex-shrink">视频</text>
					<view class="flex align-center flex-1 flex-wrap">
						<block v-for="(item, index) in newVideo" :key="index">
							<view class="img-box" v-if="!item.isPlay" @click.stop="playVideo(item, 'new', index)">
								<image src="" mode="aspectFill" lazy-load class="img" style="background-color: #000;">
								</image>
								<image src="../../../static/images/video-bg.png" mode="aspectFill" class="v-play">
								</image>
								<image src="../../../static/images/close.png" class="close"
									@click.stop="delFile(item, index, 'newVideo')"></image>
							</view>
							<view class="img-box" v-else>
								<video :src="`${read_url}${item.fileCode}`" class="img" :id="`newVideo${index}`"
									@fullscreenchange="fullscreenchange($event, index, 'new')"
									@ended="videoEnd($event, index, 'new')"></video>
							</view>
						</block>
					</view>
					<view class="flex-shrink padding-lr-24" v-if="newVideo.length < 9&&state!=5&&state!=4">
						<image src="../../../static/images/icon29.png" mode="widthFix" class="i-icon"
							@click="uploadImg('video', 'new')"></image>
					</view>
				</view>
			</view>
		</block>

		<view class="bottom-wrap">
			<view class="bottom justify-between" v-if="state == 1">
				<view class="btn left" @click="auditing(-1)">撤销</view>
				<view class="btn right" @click="auditing(2)">审核</view>
			</view>
			<view class="bottom justify-center" v-if="state == 4&&!isFinsh">
				<view class="btn3 right"
					@click="navTo(`/pages/service/accept/index?type=1&title=巡检审核&orderType=ins&orderId=${id}`)">验收
				</view>
			</view>
			<view class="bottom justify-between" v-if="state == 2">
				<view class="btn" :class="['btn', isCodeGray ? 'right' : 'gray']" @click="isCodeGray &&updateState(3)">
					开始点检</view>
				<view class="btn left" @click="transfer">转交</view>
			</view>
			<view class="bottom justify-center" v-if="state == 7">
				<view class="btn3 right" @click="receive">领取工单</view>
			</view>
			<view class="bottom justify-center" v-if="state == 5">
				<view class="btn3" style="background-color: rgba(126, 207, 81, 1);"
					@click="navTo(`/pages/service/repair/index?id=${oneInfo.emId}&type=scan&code=${oneInfo.code}&imgs=${JSON.stringify(ycPics)}&videos=${JSON.stringify(ycVideo)}&audios=${JSON.stringify(ycAudio)}&desc=${orderException}`)">
					新增维修</view>
			</view>

			<!-- <view class="bottom justify-between">
				<view class="btn left" @click="">暂停</view>
				<view class="btn right" @click="">点检完成</view>
			</view> -->
			<view class="bottom justify-center" v-if="state == 6">
				<view class="btn3 right" @click="updateState(3)">继续</view>
			</view>
			<view class="bottom justify-between" v-if="state == 3">
				<view class="btn2 left" @click="updateState(6)">暂停</view>
				<view class="btn2 right" @click="save()">保存</view>
				<view class="btn2 right" @click="updateState(4)">巡检完成</view>
			</view>
		</view>

		<view :class="longPress == '1' ? 'record-layer' : 'record-layer1'" @click="longPress = 1">
			<view :class="longPress == '1' ? 'record-box' : 'record-box1'">
				<view class="record-btn-layer">
					<button class="record-btn" :class="longPress == '1' ? '' : 'record-btn-2'"
						:style="VoiceTitle != '松开手指,取消发送' && longPress != '1'?'background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);':'background-color: rgba(0, 0, 0, 0);color:white'">
						<image src="../../../static/images/icon30.png" mode=""></image>
						<text>{{VoiceText}}</text>
					</button>
				</view>
				<!-- 语音音阶动画 -->
				<view :class="VoiceTitle != '松开手指,取消发送'?'prompt-layer prompt-layer-1':'prompt-layer1 prompt-layer-1'"
					v-if="longPress == '2'">
					<view class="prompt-loader">
						<view class="em" v-for="(item,index) in 15" :key="index"></view>
					</view>
					<text class="span">{{VoiceTitle}}</text>
				</view>
			</view>
		</view>

		<!-- 选择故障类型 -->
		<w-picker mode="selector" :options="typeList" themeColor="#30a3e0" :defaultProps="leverProps"
			default-type="dictName" @confirm="onConfirm($event, 'type')" ref="type"></w-picker>
		<!-- 选择故障原因 -->
		<w-picker mode="selector" :options="reasonList" themeColor="#30a3e0" :defaultProps="leverProps"
			default-type="dictName" @confirm="onConfirm($event, 'reason')" ref="reason"></w-picker>
		<!-- 选择设备状态 -->
		<w-picker mode="selector" :options="stateList" themeColor="#30a3e0" :defaultProps="leverProps"
			default-type="dictName" @confirm="onConfirm($event, 'state')" ref="state"></w-picker>
		<!-- 工作项 -->
		<w-picker mode="selector" :options="workState" themeColor="#30a3e0" :defaultProps="workProps" default-type="src"
			@confirm="onConfirm($event, 'selector')" ref="selector" :is-text="false" :is-img="true"></w-picker>
	</view>
</template>

<script>
	import UploadImage from '@/common/utils/upload-image.js';
	// import NFC from "./ncfModule.js";
	import {
		UPLOAD_IMAGE_URL,
		READ_FILE_URL
	} from '@/common/config.js';
	import permission from "@/common/utils/authPermiss.js";
	const recorderManager = uni.getRecorderManager();
	const innerAudioContext = uni.createInnerAudioContext();
	innerAudioContext.autoplay = false;

	var NfcAdapter;
	var MifareClassic;
	export default {
		data() {
			return {
				tabCurrent: 0,
				isCodeGray: false,
				videoContext: null,
				videoList: [],
				typeValue: {},
				reasonValue: {},
				stateValue: {},
				typeList: [],
				reasonList: [],
				stateList: [],
				leverProps: {
					value: 'dictValue',
					label: 'dictName'
				},
				read_url: READ_FILE_URL,
				oldAudio: [],
				oldPics: [],
				oldVideo: [],
				newAudio: [],
				newPics: [],
				newVideo: [],
				startPoint: {}, //记录长按录音开始点信息,用于后面计算滑动距离。
				longPress: '1', // 1显示 按住 说话 2显示 说话中
				delShow: false, // 删除提示框显示隐藏
				time: 0, //录音时长
				duration: 60000, //录音最大值ms 60000/1分钟
				tempFilePath: '', //音频路径
				startPoint: {}, //记录长按录音开始点信息,用于后面计算滑动距离。
				sendLock: true, //发送锁，当为true时上锁，false时解锁发送
				VoiceTitle: '松手结束录音',
				VoiceText: '按住 说话',
				id: '',
				oneInfo: {},
				taskList: [],
				patrolDetail: {},
				state: '',
				disposeInfo: {},
				workList: [],
				disposeResult: '',
				ycPics: [],
				ycAudio: [],
				ycVideo: [],
				orderException: '',
				oldVideoContext: null,
				newVideoContext: null,
				workState: [{
						src: '/static/images/dui.png',
						id: 2
					},
					{
						src: '/static/images/error.png',
						id: 3
					},
					{
						src: '/static/images/icon43.png',
						id: 4
					}
				],
				workProps: {
					label: 'src',
					value: 'id'
				},
				taskId: '',
				taskIndex: 0,
				isFinsh: false,
				taskChildIndex: 0,
				workIndex: 0,
				workChildx: 0,
				region: '',
				system: '',
				subSystem: '',
			}
		},
		onLoad(option) {
			this.id = option.id
			this.state = option.state
			this.isCodeGray = false
			this.init();
			uni.$on('getWorks', data => {
				data.forEach(item => {
					this.workList.push(item)
					this.taskList.push(item)
				})
			})
			uni.$on('refresh', () => {
				this.init();
			})
			uni.$on('updateWorks', (value, state) => {
				this.taskList[this.workIndex].taskList[this.workChildx].recordedValue = value
				this.taskList[this.workIndex].taskList[this.workChildx].state = state
			})

			var main = plus.android.runtimeMainActivity();
			NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
			var _nfcAdapter = NfcAdapter.getDefaultAdapter(main);
			if (_nfcAdapter == null) {
				uni.showToast({
					icon: "error",
					title: "该设备不支持NFC",
					duration: 5000
				})
			} else if (_nfcAdapter.isEnabled() == false) {
				uni.showToast({
					icon: "error",
					title: "NFC功能未打开",
					duration: 5000
				})
			} else {
				// this.$refs.popup.open("top");
				//初始化ncf 并开启监听
				this.NFCInit();
			}
		},
		onUnload() {
			uni.$off('getWorks')
			uni.$off('refresh')
			uni.$off('updateWorks')
		},
		methods: {
			init(bol) {
				let type;
				if (bol) {
					type = bol
				}
				this.ycPics = []
				this.ycAudio = []
				this.ycVideo = []
				this.oldPics = []
				this.oldAudio = []
				this.oldVideo = []
				this.newPics = []
				this.newAudio = []
				this.newVideo = []
				this.getPatrolOne(type);
				this.getPatrolDetail();
				this.getType();
				this.getReason();
				this.getState();
				this.getPatrolTask();
				this.getDispose();
			},
			navTo(path) {
				uni.navigateTo({
					url: path
				})
			},
			toSelect(e, childx, i) {
				this.workIndex = i
				this.workChildx = childx
				uni.navigateTo({
					url: `/pages/inspection/inspec-detail/select?id=${e.id}&state=${e.state}&recordedValue=${e.recordedValue}`
				})
			},
			getTree() {
				let that = this
				this.$api.post(global.apiUrls.selectEquipmentTree).then(res => {
					let info = res.data.info
					info.forEach(item => {
						item.children.forEach(child => {
							child.children.forEach(subChild => {
								if (that.oneInfo.treeId == subChild.id) {
									that.region = item.name
									that.system = child.name
									that.subSystem = subChild.name
								}
							})
						})
					})
				})
			},
			tabChange(e) {
				this.tabCurrent = e
			},
			showTask(i) {
				this.taskList[i].show = !this.taskList[i].show
			},
			changeTask(e, item) {
				console.log("state",item)
				if (this.state != 3) return;
				let state;
				if (e.detail.value) {
					state = 2
				} else {
					state = 1
				}
				this.$api.post(global.apiUrls.updatePatrolTaskState, {
					id: item.id,
					state
				}).then(res => {
					if (res.data.code != 9100) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			taskBlur(e, item, i, childx) {
				if (this.state != 3) return;
				let that = this
				this.$api.post(global.apiUrls.updatePatrolTask, {
					id: item.id,
					state: item.state,
					recordedValue: e.detail.value
				}).then(res => {
					if (res.data.code == 9100) {
						that.taskList[i].taskList[childx].recordedValue = e.detail.value
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			getPatrolOne(bol) {
				this.$api.post(global.apiUrls.selectPatrolOne, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						this.oneInfo = res.data.info
						if (bol) {
							this.isFinsh = true
						}
						this.state = this.oneInfo.state
						this.getTree();
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			getPatrolTask() {
				this.$api.post(global.apiUrls.selectPatrolTask, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						let list = res.data.info
						list.forEach(item => {
							item.show = false
						})
						this.taskList = list
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 查询巡检详情
			getPatrolDetail() {
				let that = this
				this.$api.post(global.apiUrls.selectPatrolDetail, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						let data = res.data.info
						this.patrolDetail = data
						this.orderException = this.patrolDetail.orderException
						this.ycPics = data.filePicCode
						data.fileVideoCode.forEach(item => {
							let obj = {
								isPlay: false
							}
						})
						that.ycVideo = data.fileVideoCode
						data.fileAudioCode.forEach(item => {
							let obj = {
								isPlay: false
							}
							that.ycAudio.push(obj)
						})
						that.ycAudio = data.fileAudioCode
					}
				})
			},
			// 查询巡检处理
			getDispose() {
				this.$api.post(global.apiUrls.selectPatrolDispose, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						this.disposeInfo = res.data.info
						if (this.disposeInfo.disposeResult != 'null') {
							this.disposeResult = this.disposeInfo.disposeResult
						}
						this.typeList.forEach(item => {
							if (item.dictValue == this.disposeInfo.faultType) {
								this.typeValue = item
							}
						})
						this.reasonList.forEach(item => {
							if (item.dictValue == this.disposeInfo.faultReason) {
								this.reasonValue = item
							}
						})
						this.stateList.forEach(item => {
							if (item.dictValue == this.disposeInfo.emState) {
								this.stateValue = item
							}
						})
						this.oldPics = []
						this.oldAudio = []
						this.oldVideo = []
						this.newPics = []
						this.newAudio = []
						this.newVideo = []
						if (this.disposeInfo.fileOldPicCode) {
							this.disposeInfo.fileOldPicCode.forEach(item => {
								let obj = {
									fileCode: item
								}
								this.oldPics.push(obj)
							})
						}
						if (this.disposeInfo.fileOldAudioCode) {
							this.disposeInfo.fileOldAudioCode.forEach(item => {
								let obj = {
									url: `${READ_FILE_URL}${item}`,
									isPlay: false,
									fileCode: item
									// fileName: item.fileName
								}
								this.oldAudio.push(obj)
							})
						}
						if (this.disposeInfo.fileOldVideoCode) {
							this.disposeInfo.fileOldVideoCode.forEach(item => {
								let obj = {
									isPlay: false,
									fileCode: item
								}
								this.oldVideo.push(obj)
							})
						}
						if (this.disposeInfo.fileNewPicCode) {
							this.disposeInfo.fileNewPicCode.forEach(item => {
								let obj = {
									fileCode: item
								}
								this.newPics.push(obj)
							})
						}
						if (this.disposeInfo.fileNewAudioCode) {
							this.disposeInfo.fileNewAudioCode.forEach(item => {
								let obj = {
									url: `${READ_FILE_URL}${item}`,
									isPlay: false,
									fileCode: item
									// fileName: item.fileName
								}
								this.newAudio.push(obj)
							})
						}
						if (this.disposeInfo.fileNewVideoCode) {
							this.disposeInfo.fileNewVideoCode.forEach(item => {
								let obj = {
									isPlay: false,
									fileCode: item
								}
								this.newVideo.push(obj)
							})
						}
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			auditing(e) {
				this.$api.post(global.apiUrls.updatePatrolState, {
					id: this.id,
					operation: e
				}).then(res => {
					if (res.data.code == 9100) {
						if (this.workList.length > 0) {
							this.addTask(this.id);
						} else {
							uni.showToast({
								title: '操作成功',
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateBack()
							}, 800)
						}
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			updateWorkState(e, child, childx, i) {
				if (this.state != 3) return;
				this.$api.post(global.apiUrls.updatePatrolTask, {
					id: child.id,
					state: e
				}).then(res => {
					if (res.data.code != 9100) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					} else {
						this.taskList[i].taskList[childx].state = e
					}
				})
			},
			// 新增工作项
			addTask(id) {
				let arr = []
				this.workList.forEach(item => {
					arr.push(item.id)
				})
				this.$api.post(global.apiUrls.insertPatrolTask, {
					id: id,
					taskIds: arr.join(',')
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 9100) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 800)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				}).catch(() => {
					uni.hideLoading()
				})
			},
			playVideo(e, type, i) {
				let that = this;
				if (type == 'old') {
					this.oldVideoContext = uni.createVideoContext(`oldVideo${i}`);
					this.oldVideo[i].isPlay = true
					setTimeout(() => {
						that.oldVideoContext.requestFullScreen(0);
						that.oldVideoContext.play();
					}, 200);
				} else if (type == 'new') {
					this.newVideoContext = uni.createVideoContext(`newVideo${i}`);
					this.newVideo[i].isPlay = true
					setTimeout(() => {
						that.newVideoContext.requestFullScreen(0);
						that.newVideoContext.play();
					}, 200);
				} else {
					this.videoContext = uni.createVideoContext(`myVideo${i}`);
					this.videoList[i].isPlay = true
					setTimeout(() => {
						that.videoContext.requestFullScreen(0);
						that.videoContext.play();
					}, 200);
				}
			},
			fullscreenchange(e, i) {
				console.log(e);
				// 退出全屏时
				if (!e.detail.fullScreen) {
					this.videoList[i].isPlay = false;
					this.videoContext.pause();
				}
			},
			videoEnd(e, type) {
				this.videoContext.exitFullScreen();
				this.videoList[i].isPlay = false;
			},
			playAudio(item, i, type) {
				if (this.tabCurrent == 1) {
					this.ycAudio[i].isPlay = !this.ycAudio[i].isPlay
					innerAudioContext.src = `${READ_FILE_URL}${item.fileCode}`
					console.log(this.ycAudio[i], item, 3333333)
					if (this.ycAudio[i].isPlay) {
						this.ycAudio.forEach((res, index) => {
							if (index !== i) {
								res.isPlay = false
							}
						})
						innerAudioContext.play();
						this.$forceUpdate();
					} else {
						this.ycAudio.forEach((res, index) => {
							res.isPlay = false
						})
						innerAudioContext.pause();
						this.$forceUpdate();
					}
					innerAudioContext.onEnded(() => {
						this.ycAudio[i].isPlay = false
						this.$forceUpdate();
					})
				} else if (this.tabCurrent == 2) {
					if (type == 'old') {
						this.oldAudio[i].isPlay = !this.oldAudio[i].isPlay
						innerAudioContext.src = `${READ_FILE_URL}${item.fileCode}`
						this.newAudio.forEach((res, index) => {
							res.isPlay = false
						})
						if (this.oldAudio[i].isPlay) {
							this.oldAudio.forEach((res, index) => {
								if (index !== i) {
									res.isPlay = false
								}
							})
							innerAudioContext.play();
							this.$forceUpdate();
						} else {
							this.oldAudio.forEach((res, index) => {
								res.isPlay = false
							})
							innerAudioContext.pause();
							this.$forceUpdate();
						}
						innerAudioContext.onEnded(() => {
							this.oldAudio[i].isPlay = false
							this.$forceUpdate();
						})
					} else {
						this.newAudio[i].isPlay = !this.newAudio[i].isPlay
						innerAudioContext.src = `${READ_FILE_URL}${item.fileCode}`
						this.oldAudio.forEach((res, index) => {
							res.isPlay = false
						})
						if (this.newAudio[i].isPlay) {
							this.newAudio.forEach((res, index) => {
								if (index !== i) {
									res.isPlay = false
								}
							})
							innerAudioContext.play();
							this.$forceUpdate();
						} else {
							this.newAudio.forEach((res, index) => {
								res.isPlay = false
							})
							innerAudioContext.pause();
							this.$forceUpdate();
						}
						innerAudioContext.onEnded(() => {
							this.newAudio[i].isPlay = false
							this.$forceUpdate();
						})
					}
				}
			},
			toggleTab(ref, id, i, childx) {
				if (this.state == 5) return;
				if (ref == 'selector') {
					if (this.state == 3) {
						this.taskId = id
						this.taskIndex = i
						this.taskChildIndex = childx
						this.$refs[ref].show();
					}
				} else {
					this.$refs[ref].show();
				}
			},
			onConfirm(e, type) {
				console.log(e)
				if (type == 'type') {
					this.typeValue = {
						dictValue: e.value,
						dictName: e.result
					}
				} else if (type == 'reason') {
					this.reasonValue = {
						dictValue: e.value,
						dictName: e.result
					}
				} else if (type == 'state') {
					this.stateValue = {
						dictValue: e.value,
						dictName: e.result
					}
				} else {
					this.$api.post(global.apiUrls.updatePatrolTask, {
						id: this.taskId,
						state: e.value
					}).then(res => {
						if (res.data.code == 9100) {
							this.taskList[this.taskIndex].taskList[this.taskChildIndex].state = e.value
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					})
				}
			},
			// 查询故障类别
			getType() {
				this.$api.post(global.apiUrls.selectType, {
					dictTypeCode: 'TYPE_REP_MAINTENANCE'
				}).then(res => {
					if (res.data.code == 9100) {
						this.typeList = res.data.info
					}
				})
			},
			// 查询故障原因
			getReason() {
				this.$api.post(global.apiUrls.selectType, {
					dictTypeCode: 'TYPE_REP_REASON'
				}).then(res => {
					if (res.data.code == 9100) {
						this.reasonList = res.data.info
					}
				})
			},
			// 查询设备状态
			getState() {
				this.$api.post(global.apiUrls.selectType, {
					dictTypeCode: 'TYPE_EM_STATE'
				}).then(res => {
					if (res.data.code == 9100) {
						this.stateList = res.data.info
					}
				})
			},
			async checkRecord(e) {
				try {
					let checkResult = await permission("record");
					console.log("检测信息：", checkResult);
					if (checkResult.code == 1) {
						let result = checkResult.data;
						if (result == 1) {
							console.log("授权成功!");
							let that = this
							if (this.isTouchEnd) return
							console.log(recorderManager)
							recorderManager.onStop((res) => {
								console.log(777);
								console.log(res);
								// that.userInfo.remark = res.tempFilePath;
							})
							console.log(555, recorderManager);
							that.startPoint = e.touches[0]; //记录长按时开始点信息，后面用于计算上划取消时手指滑动的距离。
							that.longPress = '2';
							that.VoiceText = '说话中...';
							const options = {
								// duration: that.duration, // 指定录音的时长，单位 ms
								// sampleRate: 16000, // 采样率
								numberOfChannels: 1, // 录音通道数
								// encodeBitRate: 96000, // 编码码率
								format: 'mp3', // 音频格式，有效值 aac/mp3
								frameSize: 10, // 指定帧大小，单位 KB
							}
							recorderManager.start(options);
							// 监听音频开始事件
							that.sendLock = false; //长按时是不上锁的。
							recorderManager.onStart((res) => {
								console.log(1111222)
							})
							// 	},
							// 	fail: (res) => {
							// 		uni.showToast({
							// 			title: '喊话失败',
							// 			icon: 'none'
							// 		})
							// 	}
							// })
						}
						if (result == 0) {
							console.log("授权已拒绝!");
							uni.showToast({
								title: '麦克风权限未开启',
								icon: 'none'
							})
						}
						if (result == -1) {
							console.log("您已永久拒绝麦克风权限，请在应用设置中手动打开!");
							uni.showToast({
								title: '您已永久拒绝麦克风权限，请在应用设置中手动打开!',
								icon: 'none'
							})
						}
					}
				} catch (err) {
					console.log("授权失败：", err);
				}
			},
			// 语音开始
			longpressBtn(e) {
				this.isTouchEnd = false
				this.checkRecord(e);
			},
			handleTouchMove(e) {
				//touchmove时触发
				var moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
				if (Math.abs(moveLenght) > 70) {
					// wx.showToast({
					//       title: "松开手指,取消发送",
					//       icon: "none",
					//       duration: 60000
					// });
					// console.log("松开手指,取消发送");
					this.VoiceTitle = "松开手指,取消发送";
					this.VoiceText = '松开手指,取消发送';
					this.delBtn()
					this.sendLock = true; //触发了上滑取消发送，上锁
				} else {
					// wx.showToast({
					//       title: "正在录音，上划取消发送",
					//       icon: "none",
					//       duration: 60000
					// });
					this.VoiceTitle = "松手结束录音";
					this.VoiceText = '松手结束录音';
					this.sendLock = false; //上划距离不足，依然可以发送，不上锁
				}
			},
			touchendBtn(e, type) {
				console.log('end', recorderManager)
				this.isTouchEnd = true
				this.longPress = '1';
				this.VoiceText = '按住 说话';
				this.VoiceTitle = '松手结束录音'
				recorderManager.onStop((res) => {
					console.log(this.sendLock);
					if (this.sendLock) {
						//上锁不发送
					} else { //解锁发送，发送网络请求
						if (res.duration < 1000)
							uni.showToast({
								title: "录音时间太短",
								icon: "none",
								duration: 1000
							});
						else {
							// this.userInfo.remark = res.tempFilePath
							console.log('end', res)
							let that = this
							uni.showLoading({
								mask: true,
								title: '上传中...'
							})
							uni.uploadFile({
								url: UPLOAD_IMAGE_URL,
								filePath: res.tempFilePath,
								fileType: 'audio',
								name: 'files',
								header: {
									'Authorization': global.token
								},
								formData: {
									'module': '',
									'dir': ''
								},
								success: (child) => {
									console.log(child)
									let data = JSON.parse(child.data);
									if (data.code == 9100) {
										// this.audio = data.info[0]
										const now = new Date();
										const year = now.getFullYear();
										const MM = `0${now.getMonth() + 1}`
										const month = MM.slice(-2)
										const dd = `0${now.getDate()}`
										const day = dd.slice(-2)
										const hh = `0${now.getHours()}`.slice(-2)
										const mm = `0${now.getMinutes()}`.slice(-2)
										const ss = `0${now.getSeconds()}`.slice(-2)
										let time = year + month + day + hh + mm + ss
										let path = `${READ_FILE_URL}${data.info[0]}`
										let obj = {
											url: path,
											isPlay: false,
											fileCode: data.info[0],
											fileName: time,
											isUpload: true
										}
										if (type == 'old') {
											that.oldAudio.push(obj)
										} else if (type == 'new') {
											that.newAudio.push(obj)
										} else if (type == 'yc') {
											that.ycAudio.push(obj)
										}
									} else {}
								},
								complete: () => {
									uni.hideLoading()
								}
							});
						}
					}
				})

				// this.recordingTimer(this.time)
				recorderManager.stop(); //结束录音
			},
			touchAudioBtn() {

			},
			delBtn() {
				this.delShow = false;
				this.time = 0
				// this.VoiceTitle = '松手结束录音'
			},

			uploadImg(type, state) {
				if (type == 'img') {
					uni.chooseImage({
						sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
						sourceType: ["album", "camera"],
						success: (res) => {
							const tempFilePaths = res.tempFilePaths;
							new UploadImage(tempFilePaths, {
								complete: (item) => {
									if (state == 'old') {
										item.forEach(data => {
											let obj = {
												fileCode: data,
												isUpload: true
											}
											this.oldPics.push(obj)
										})
									} else if (state == 'new') {
										item.forEach(data => {
											let obj = {
												fileCode: data,
												isUpload: true
											}
											this.newPics.push(obj)
										})
									} else if (state == 'yc') {
										item.forEach(data => {
											let obj = {
												fileCode: data,
												isUpload: true
											}
											this.ycPics.push(obj)
										})
									}
								}
							})
						}
					})
				} else if (type == 'video') {
					uni.chooseVideo({
						maxDuration: 60,
						count: 1,
						success: res => {
							uni.showLoading({
								title: '上传中...'
							});
							let videoFile = res.tempFilePath;
							let size = Math.ceil(res.size / 1024 / 1024);
							if (size > 50) {
								uni.hideLoading();
								uni.showToast({
									title: '视频大小不能超过50M',
									icon: 'none'
								})
								return
							}
							this.uploadVideo(res, state)
						}
					})
				}
			},
			uploadVideo(file, state) {
				let _this = this
				// const aliyunFileKey = 'image/' + new Date().getTime() + Math.floor(Math.random() * 150) + '.mp4';
				uni.uploadFile({
					url: UPLOAD_IMAGE_URL,
					files: [{
						name: 'files',
						file: file.tempFile,
						uri: file.tempFilePath
					}],
					// name: 'file',
					fileType: 'video',
					header: {
						'Authorization': global.token || ''
						// "Content-Type": "multipart/form-data"
					},
					// formData: {
					// 	'files': file.tempFile
					// },
					success: res => {
						console.log(res, 'resres')
						let data = JSON.parse(res.data)
						if (data.code == 9100) {
							uni.hideLoading();
							// let fileData = {}
							let info = data.info
							if (state == 'old') {
								info.forEach(item => {
									let obj = {
										fileCode: item,
										isPlay: false,
										isUpload: true
									}
									_this.oldVideo.push(obj)
								})
							} else if (state == 'new') {
								info.forEach(item => {
									let obj = {
										fileCode: item,
										isPlay: false,
										isUpload: true
									}
									_this.newVideo.push(obj)
								})
							} else if (state == 'yc') {
								info.forEach(item => {
									let obj = {
										fileCode: item,
										isPlay: false,
										isUpload: true
									}
									_this.ycVideo.push(obj)
								})
							}
						} else {
							uni.hideLoading();
							uni.showToast({
								title: '上传失败，请重试',
								icon: 'none'
							})
						}
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				})
			},
			// 删除文件
			delFile(e, i, type) {
				// return
				if (type == 'oldAudio') {
					this.oldAudio.splice(i, 1)
				} else if (type == 'oldImg') {
					this.oldPics.splice(i, 1)
				} else if (type == 'oldVideo') {
					this.oldVideo.splice(i, 1)
				} else if (type == 'newAudio') {
					this.newAudio.splice(i, 1)
				} else if (type == 'newImg') {
					this.newPics.splice(i, 1)
				} else if (type == 'newVideo') {
					this.newVideo.splice(i, 1)
				} else if (type == 'ycImg') {
					this.ycPics.splice(i, 1)
				} else if (type == 'ycVideo') {
					this.ycVideo.splice(i, 1)
				} else if (type == 'ycAudio') {
					this.ycAudio.splice(i, 1)
				}
				if (!e.isUpload) {
					this.$api.post(global.apiUrls.deleteFile, {
						fileCode: e.fileCode
					}).then(res => {
						if (res.data.code == 9100) {
							console.log(res)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					})
				}
			},
			updateState(e) {
				let isComplete = true
				if (e == 4) {
					for (let i = 0; i < this.taskList.length; i++) {
						let item = this.taskList[i]
						if (item.state == 1) {
							isComplete = false
							// uni.showToast({
							// 	title: '请设置巡检工作项',
							// 	icon: 'none'
							// })
							break;
						}
					}
				}
				if (isComplete) {
					this.$api.post(global.apiUrls.updatePatrolState, {
						id: this.id,
						operation: e, //-1审核驳回，2审核完成，3巡检开工，4巡检完成，5验收，6暂停
					}).then(res => {
						if (res.data.code == 9100) {
							uni.showToast({
								title: '操作成功',
								icon: 'none'
							})
							this.init(true);
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					})
				}
			},
			// 转交
			transfer() {
				this.$api.post(global.apiUrls.transferPatrol, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 800)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 领取工单
			receive() {
				this.$api.post(global.apiUrls.receivePatrol, {
					id: this.id
				}).then(res => {
					if (res.data.code == 9100) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						setTimeout(() => {
							// uni.navigateBack()
							let title = '我处理的'
							let state = 6
							uni.redirectTo({
								url: `/pages/service/order/index?title=${title}&state=${state}`
							})
						}, 800)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 修改巡检处理
			updateDispose() {
				let oldAudioCode = []
				let newAudioCode = []
				let oldPics = []
				let newPics = []
				let oldVideo = []
				let newVideo = []
				this.oldAudio.forEach(item => {
					oldAudioCode.push(item.fileCode)
				})
				this.newAudio.forEach(item => {
					newAudioCode.push(item.fileCode)
				})
				this.oldPics.forEach(item => {
					oldPics.push(item.fileCode)
				})
				this.newPics.forEach(item => {
					newPics.push(item.fileCode)
				})
				this.oldVideo.forEach(item => {
					// if (item.isUpload) {

					// }
					oldVideo.push(item.fileCode)
				})
				this.newVideo.forEach(item => {
					newVideo.push(item.fileCode)
				})
				this.$api.post(global.apiUrls.updatePatrolDispose, {
					id: this.id,
					faultType: this.typeValue.dictValue || 0,
					faultReason: this.reasonValue.dictValue || 0,
					emState: this.stateValue.dictValue || 0,
					disposeResult: this.disposeResult,
					fileOldPicCode: oldPics.join(','),
					fileOldAudioCode: oldAudioCode.join(','), //维修前音频
					fileOldVideoCode: oldVideo.join(','), //维修前视频
					fileNewPicCode: newPics.join(','), //维修后图片
					fileNewAudioCode: newAudioCode.join(','), //维修后音频
					fileNewVideoCode: newVideo.join(',') //维修后视频
				}).then(res => {
					if (res.data.code == 9100) {
						uni.showToast({
							title: '保存成功',
							icon: 'none'
						})
						this.init();
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 修改巡检详情
			updateDetail() {
				let imgs = []
				let audio = []
				let video = []
				this.ycPics.forEach(item => {
					imgs.push(item.fileCode)
				})
				this.ycAudio.forEach(item => {
					audio.push(item.fileCode)
				})
				this.ycVideo.forEach(item => {
					video.push(item.fileCode)
				})
				this.$api.post(global.apiUrls.updatePatrolDetail, {
					id: this.id,
					orderException: this.orderException,
					filePicCode: imgs.join(','),
					fileAudioCode: audio.join(','),
					fileVideoCode: video.join(',')
				}).then(res => {
					if (res.data.code != 9100) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						return
					}
					this.updateDispose();
				})
			},
			async save() {
				await this.updateDetail();
			},
			NFCInit() {
				try {

					var main = plus.android.runtimeMainActivity();
					var Intent = plus.android.importClass('android.content.Intent');
					// console.log(Intent);
					var Activity = plus.android.importClass('android.app.Activity');
					//console.log(Activity);
					var PendingIntent = plus.android.importClass('android.app.PendingIntent');
					// console.log(PendingIntent);
					var IntentFilter = plus.android.importClass('android.content.IntentFilter');
					var NdefRecord = plus.android.importClass('android.nfc.NdefRecord')
					var NdefMessage = plus.android.importClass('android.nfc.NdefMessage')
					MifareClassic = plus.android.importClass("android.nfc.tech.MifareClassic");

					NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');

					var _nfcAdapter = NfcAdapter.getDefaultAdapter(main);


					var ndef = new IntentFilter('android.nfc.action.NDEF_DISCOVERED'); //NfcAdapter.ACTION_NDEF_DISCOVERED

					var tag = new IntentFilter('android.nfc.action.TAG_DISCOVERED'); //NfcAdapter.ACTION_TECH_DISCOVERED
					console.log(tag);
					var tech = new IntentFilter('android.nfc.action.TECH_DISCOVERED');

					var intentFiltersArray = [ndef, tag, tech];

					var techListsArray = [
						['android.nfc.tech.Ndef'],
						['android.nfc.tech.IsoDep'],
						['android.nfc.tech.NfcA'],
						['android.nfc.tech.NfcB'],
						['android.nfc.tech.NfcF'],
						['android.nfc.tech.Nfcf'],
						['android.nfc.tech.Nfef'],
						['android.nfc.tech.Ndef'],
						['android.nfc.tech.NfcV'],
						['android.nfc.tech.NdefFormatable'],
						['android.nfc.tech.MifareClassi'],
						['android.nfc.tech.MifareUltralight']
					];
					var _intent = new Intent(main, main.getClass());
					// console.log(_intent);
					_intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

					var pendingIntent = PendingIntent.getActivity(main, 0, _intent, 0);
					var that = this;
					//监听贴卡到手机事件 
					plus.globalEvent.addEventListener('newintent', e => {
						//获取ic卡数据
						that.NFCReadUID()
						//销毁监听事件
						plus.globalEvent.removeEventListener("newintent", false);
					});
					if (_nfcAdapter == null) {} else if (_nfcAdapter.isEnabled() == false) {} else {
						_nfcAdapter.enableForegroundDispatch(main, pendingIntent, IntentFilter, techListsArray);

					}
				} catch (e) {
					//TODO handle the exception
				}
			},
			NFCReadUID() {
				var main = plus.android.runtimeMainActivity();
				var _intent = main.getIntent();
				var _action = _intent.getAction();

				if (NfcAdapter.ACTION_NDEF_DISCOVERED == _action || NfcAdapter.ACTION_TAG_DISCOVERED == _action ||
					NfcAdapter.ACTION_TECH_DISCOVERED == _action) {

					var Tag = plus.android.importClass('android.nfc.Tag');
					var tagFromIntent = _intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

					// 获取卡片支持的技术列表
					var techList = tagFromIntent.getTechList();

					// 判断卡片类型
					var cardType = "Unknown";
					if (techList.includes("android.nfc.tech.Ndef")) {
						cardType = "NDEF";
					} else if (techList.includes("android.nfc.tech.MifareClassic")) {
						cardType = "Mifare Classic";
					} else if (techList.includes("android.nfc.tech.NfcA")) {
						cardType = "NfcA";
					} else if (techList.includes("android.nfc.tech.NfcV")) {
						cardType = "NfcV";
					} else if (techList.includes("android.nfc.tech.IsoDep")) {
						cardType = "IsoDep";
					}


					// 继续处理卡片数据
					var bind_code = _intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
					var rawMsgs = _intent.getParcelableArrayExtra("android.nfc.extra.NDEF_MESSAGES");
					var bind_codes = this.Bytes2HexString(bind_code);
					var tagUid = this.bytesToHexString(tagFromIntent.getId());
					var tagid = this.reverseTwo(tagUid);
					let icId = parseInt(tagid, 16).toString();
					icId = icId.length < 10 ? (Array(10).join(0) + icId).slice(-10) : icId;
					var parsedData = this.parseNdefMessages(rawMsgs);
					if (icId) {
						let nfcCode = parsedData.substring(3)
						this.$api.post(global.apiUrls.selectNFCPatrolOne, {
							id: this.id,
							code: nfcCode
						}).then(({
							data
						}) => {
							console.error(data)
							if (data.code === 9100) {
								this.isCodeGray = true
							} else {
								uni.showToast({
									icon: "none",
									title: data.msg,
									duration: 5000
								})
							}
						}).catch(error => {
							console.log(error)
						})
					} else {
						uni.showToast({
							title: "读取数据失败,请重新读取",
							icon: 'none'
						});
					}
				}
			},
			parseNdefMessages(rawMsgs) {
				if (!rawMsgs || rawMsgs.length === 0) {
					console.warn("No NDEF messages found.");
					return null;
				}
				var parsedData = [];
				for (var i = 0; i < rawMsgs.length; i++) {
					var ndefMessage = rawMsgs[i];
					var records = ndefMessage.getRecords();
					for (var j = 0; j < records.length; j++) {
						var record = records[j];
						var payload = record.getPayload();
						var payloadType = record.getTnf();

						var payloadBytes = plus.android.newObject("byte[]", payload);
						var payloadString = plus.android.newObject("java.lang.String", payloadBytes);
						var byteArray = payloadString.value.value;
						var resultString = this.bytesToString(byteArray);

						return resultString
					}
				}

				return '';
			},
			bytesToString(bytes) {
				let result = [];
				for (let i = 0; i < bytes.length; i++) {
					let byte = bytes[i];
					if (byte < 0x80) {
						// 单字节字符
						result.push(String.fromCharCode(byte));
					} else if (byte < 0xE0) {
						// 双字节字符
						let charCode = ((byte & 0x1F) << 6) | (bytes[++i] & 0x3F);
						result.push(String.fromCharCode(charCode));
					} else if (byte < 0xF0) {
						// 三字节字符
						let charCode = ((byte & 0x0F) << 12) | ((bytes[++i] & 0x3F) << 6) | (bytes[++i] & 0x3F);
						result.push(String.fromCharCode(charCode));
					} else {
						// 四字节字符（不常见）
						let charCode = ((byte & 0x07) << 18) | ((bytes[++i] & 0x3F) << 12) | ((bytes[++i] & 0x3F) << 6) | (
							bytes[++i] & 0x3F);
						result.push(String.fromCharCode(charCode));
					}
				}
				return result.join("");
			},
			reverseTwo(str) {
				var str1 = "";
				for (var i = 1; i <= str.length; i++) {
					str1 += str[i - 1];
					if (i % 2 == 0) {
						if (i == str.length) {
							break;
						}
						str1 += ":";
					}
				}
				var str2 = "";
				for (var i = str1.split(":").length - 1; i >= 0; i--) {
					str2 += str1.split(":")[i];
				}
				return str2;
			},
			bytesToHexString(inarray) {
				var i, j, x;
				var hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
					"B", "C", "D", "E", "F"
				];
				var out = "";
				for (j = 0; j < inarray.length; ++j) {
					x = parseInt(inarray[j]) & 0xff;
					i = (x >> 4) & 0x0f;
					out += hex[i];
					i = x & 0x0f;
					out += hex[i];
				}
				return out;
			},

			//将byte[] 转为Hex，
			Bytes2HexString(arrBytes) {
				var str = '';
				for (var i = 0; i < arrBytes.length; i++) {
					var tmp;
					var num = arrBytes[i];
					if (num < 0) {
						//Java中数值是以补码的形式存在的，应用程序展示的十进制是补码对应真值。补码的存在主要为了简化计算机底层的运算，将减法运算直接当加法来做
						tmp = (255 + num + 1).toString(16);
					} else {
						tmp = num.toString(16);
					}
					if (tmp.length == 1) {
						tmp = '0' + tmp;
					}
					str += tmp;
				}
				return str;
			},
			byteToString(arr) {
				if (typeof arr === 'string') {
					return arr;
				}
				var str = '',
					_arr = arr;
				for (var i = 0; i < _arr.length; i++) {
					var one = _arr[i].toString(2),
						v = one.match(/^1+?(?=0)/);
					if (v && one.length == 8) {
						var bytesLength = v[0].length;
						var store = _arr[i].toString(2).slice(7 - bytesLength);
						for (var st = 1; st < bytesLength; st++) {
							store += _arr[st + i].toString(2).slice(2);
						}
						str += String.fromCharCode(parseInt(store, 2));
						i += bytesLength - 1;
					} else {
						str += String.fromCharCode(_arr[i]);
					}
				}
				return str;
			},
			hexToString(str) {
				var val = "",
					len = str.length / 2;
				for (var i = 0; i < len; i++) {
					val += String.fromCharCode(parseInt(str.substr(i * 2, 2), 16));
				}
				console.log(val, '16进制转字符串')
				// this.utf8to16(val);
				return val
			},
			//处理中文乱码问题
			utf8to16(str) {
				var that = this
				var out, i, len, c;
				var char2, char3;
				out = "";
				len = str.length;
				i = 0;
				while (i < len) {
					c = str.charCodeAt(i++);
					switch (c >> 4) {
						case 0:
						case 1:
						case 2:
						case 3:
						case 4:
						case 5:
						case 6:
						case 7:
							out += str.charAt(i - 1);
							break;
						case 12:
						case 13:
							char2 = str.charCodeAt(i++);
							out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
							break;
						case 14:
							char2 = str.charCodeAt(i++);
							char3 = str.charCodeAt(i++);
							out += String.fromCharCode(((c & 0x0F) << 12) |
								((char2 & 0x3F) << 6) |
								((char3 & 0x3F) << 0));
							break;
					}
				}
				console.log(out, 'out')
				return out;

			},

		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background-color: #f3f5f8;
	}

	.tab-box {
		position: fixed;
		width: 100%;
		top: 150rpx;
		display: flex;
		height: 88rpx;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		z-index: 99;

		.tab {
			width: 33%;
			text-align: center;
			position: relative;
			font-size: 28rpx;
			height: 88rpx;
			line-height: 88rpx;
			color: #7F7F7F;
		}

		.tab-active {
			color: #333;

			&::after {
				width: 82rpx;
				height: 6rpx;
				content: '';
				position: absolute;
				bottom: 0;
				left: 0;
				right: 0;
				margin: 0 auto;
				background-color: #555;
			}
		}
	}

	.box {
		background-color: #fff;
		padding: 0 24rpx;

		.title {
			font-size: 34rpx;
			font-weight: bold;
		}

		.t-icon {
			width: 44rpx;
			margin-right: 24rpx;
		}

		.item {
			font-size: 28rpx;
		}

		.work-icon {
			width: 54rpx;
		}

		.add-r-icon {
			width: 42rpx;
			height: 42rpx;
		}

		.no-data {
			min-height: 260rpx;

			.img {
				width: 160rpx;
				margin-top: 32rpx;
			}
		}

		.work-status {
			width: 60rpx;
			height: 60rpx;
		}

		.hidden {
			width: 44rpx;
			height: 44rpx;
		}

		.show {
			width: 44rpx;
			height: 44rpx;
			transform: rotate(90deg);
		}

		.work-pla-ipt {
			font-size: 26rpx;
		}

		.work-ipt {
			padding: 0 12rpx;
			text-align: right;
			width: 200rpx;
		}

		.yc-imgs {
			width: 120rpx;
			height: 120rpx;
			margin-right: 12rpx;
			margin-bottom: 12rpx;
			position: relative;

			.close {
				width: 32rpx;
				height: 32rpx;
				position: absolute;
				z-index: 9;
				top: -8rpx;
				right: -8rpx;
			}

			.img {
				width: 100%;
				height: 100%;
			}

			.v-play {
				position: absolute;
				width: 44rpx;
				height: 44rpx;
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				margin: auto;
			}
		}

		.yc-audio {
			.play {
				width: 32rpx;
				height: 32rpx;
				flex-shrink: 0;
				margin-right: 12rpx;
			}

			.audio-url {
				color: #6c8bb6;
				text-decoration: underline;
			}
		}

		.yc-tar {
			width: 100%;
			height: 160rpx;
			border: 1rpx solid #c3c3c3;
			border-radius: 16rpx;
			padding: 12rpx;
			font-size: 28rpx;
		}

		.pla-tar {
			color: #c3c3c3;
		}

		.sh-label {
			width: 200rpx;
		}

		.tar {
			width: 100%;
			height: 160rpx;
			border: 1rpx solid #c3c3c3;
			border-radius: 16rpx;
			padding: 12rpx;
			font-size: 28rpx;
		}

		.pla-tra {
			color: #c3c3c3;
		}

		.tra {
			font-size: 26rpx;
			padding: 24rpx;
			height: 150rpx;
		}

		.cl-item {
			padding: 32rpx 0;

			.label {
				margin-right: 24rpx;
			}

			.play {
				width: 32rpx;
				height: 32rpx;
				flex-shrink: 0;
				margin-right: 12rpx;
			}

			.audio {
				color: #6c8bb6;
				text-decoration: underline;
			}

			.img-box {
				width: 32%;
				height: 100rpx;
				margin-right: 1.3%;
				position: relative;
				margin-bottom: 12rpx;

				&:nth-of-type(3n) {
					margin-right: 0;
				}

				.v-play {
					width: 44rpx;
					height: 44rpx;
					position: absolute;
					top: 0;
					bottom: 0;
					left: 0;
					right: 0;
					margin: auto;
				}

				.img {
					width: 100%;
					height: 100%;
				}

				.close {
					width: 32rpx;
					height: 32rpx;
					position: absolute;
					z-index: 9;
					top: -8rpx;
					right: -8rpx;
				}
			}

			.a-icon {
				width: 68rpx;
			}

			.i-icon {
				width: 80rpx;
			}
		}
	}

	.bottom-wrap {
		height: 140rpx;

		.bottom {
			padding: 24rpx 32rpx;
			position: fixed;
			bottom: 0;
			height: 140rpx;
			box-sizing: border-box;
			display: flex;
			width: 100%;
			z-index: 99;

			.btn {
				width: 286rpx;
				height: 88rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 88rpx;
				color: #fff;
				font-size: 34rpx;
			}

			.btn2 {
				width: 30%;
				height: 88rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 88rpx;
				color: #fff;
				font-size: 34rpx;
			}

			.btn3 {
				width: 50%;
				height: 88rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 88rpx;
				color: #fff;
				font-size: 34rpx;
			}

			.left {
				background-color: #d9001b;
			}

			.right {
				background-color: #0f68f0;
			}

			.gray {
				background-color: gray;
			}

			.lingqu {
				background-color: #f85d76;
			}
		}
	}

	.select-icon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 20rpx;
	}
</style>